import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export let constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',  //关闭窗口
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '大数据平台', icon: 'chart', affix: true }
      }
    ]
  }
]

let adminRouter= [
  {
    path: '/customerManage',
    component: Layout,
    meta: { title: '客户管理', icon: 'component', noCache: true },
    children: [
      {
        path: 'resident',
        component: () => import(/* webpackChunkName: "resident" */ '@/views/customerManage/resident'),
        name: 'resident',
        meta: { title: '居民客户',icon: 'user'}
      },
      {
        path: 'user',
        component: () => import(/* webpackChunkName: "user" */ '@/views/customerManage/user'),
        name: 'user',
        meta: { title: '非居民客户',icon: 'user' }
      },
      {
        name: 'configure',
        path: '/configure',
        component: () => import('@/views/configManage/index'), // Parent router-view
        meta: { title: '配置管理', icon: 'component' },
        redirect: '/customerManage/configure',
        children: [
          {
            path: 'project',
            component: () => import(/* webpackChunkName: "project" */ '@/views/configManage/project'),
            name: 'project',
            meta: { title: '项目配置',icon: 'user'}
          },
          {
            path: 'customer',
            component: () => import(/* webpackChunkName: "customer" */ '@/views/sysManage/task'),
            name: 'customer',
            meta: { title: '客户类型配置',icon: 'tree' }
          },
          {
            path: 'contract',
            component: () => import(/* webpackChunkName: "contract" */ '@/views/sysManage/task'),
            name: 'contract',
            meta: { title: '合同类型配置',icon: 'tree' }
          },
          {
            path: 'energy',
            component: () => import(/* webpackChunkName: "energy" */ '@/views/sysManage/task'),
            name: 'energy',
            meta: { title: '用能性质配置',icon: 'tree' }
          },
          {
            path: 'channel',
            component: () => import(/* webpackChunkName: "channel" */ '@/views/sysManage/task'),
            name: 'channel',
            meta: { title: '收支渠道配置',icon: 'tree' }
          }
        ]
      }
    ]
  },
  {
    path: '/sysManage',
    component: Layout,
    meta: { title: '安检管理', icon: 'component', noCache: true },
    children: [
      {
        path: 'checkPlan',
        component: () => import(/* webpackChunkName: "checkPlan" */ '@/views/sysManage/checkPlan'),
        name: 'checkPlan',
        meta: { title: '安检计划',icon: 'user'}
      },
      {
        path: 'task',
        component: () => import(/* webpackChunkName: "task" */ '@/views/sysManage/task'),
        name: 'task',
        meta: { title: '安检任务',icon: 'tree' }
      },
      {
        path: '/analysis',
        name: 'analysis',
        hidden: true,
        meta: { title: '安检分析',icon: 'tree' },
        component: () => import(/* webpackChunkName: "analysis" */ '@/views/sysManage/analysis'),
      },
      {
        path: 'danger',
        component: () => import(/* webpackChunkName: "role" */ '@/views/sysManage/danger'),
        name: 'danger',
        meta: { title: '安检隐患',icon: 'people' }
      },
      {
        path: '/configuration',
        name: 'configuration',
        hidden: true,
        meta: { title: '隐患配置',icon: 'tree' },
        component: () => import(/* webpackChunkName: "configuration" */ '@/views/sysManage/configuration'),
      },
      // {
      //   path: 'role',
      //   component: () => import(/* webpackChunkName: "role" */ '@/views/sysManage/role'),
      //   name: 'role',
      //   meta: { title: '警告管理',icon: 'people' }
      // }
    ]
  },
]
constantRoutes= constantRoutes.concat(adminRouter)

export const asyncRoutes = [  ];
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

// router.addRoutes(constantRoutes)
export default router
